package file_ru_chu;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.io.*;
public class Make_file {
	StringBuffer str = new StringBuffer();
	ObjectOutputStream outStream;
	ObjectInputStream inStream;
	List rclasss = new LinkedList<>();
	void write(List classs) throws IOException {
		for(int i=0;i<classs.size();i++) {
			str.append(String.join(",",(List)classs.get(i))+"\n");
		}
		String file = str.toString();
		try {
            //创建一个ObjectOutputStream输出流
			outStream = new ObjectOutputStream(new FileOutputStream("C:\\Users\\19731\\Desktop\\大二上学期\\java\\file\\课程列表.txt"));
            //将对象序列化到文件filePath
            outStream.writeObject(file);
//            outStream.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
		finally {
        	outStream.close();
        }
	}
	
	void read() throws IOException {
		try {
			inStream = new ObjectInputStream(new FileInputStream("C:\\Users\\19731\\Desktop\\大二上学期\\java\\file\\课程列表.txt"));
            String readfile = (String)inStream.readObject();
            inStream.close();
            List<String> list = Arrays.asList(readfile.split("\n"));
            for(int i = 0;i < list.size();i++) {
            	String list0 = (String)list.get(i);
            	List<String> list1 = Arrays.asList(list0.split(","));
            	rclasss.add(list1);
            }
            
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
		finally {
        	inStream.close();
        }
	}
}